import AddNodeCommand from '@/components/flow/cmd/AddNodeCommand.js';
import FlowModelInstance from '@/components/flow/typs/FlowModelInstance.js';

export class NewBranchCommand extends AddNodeCommand {
  ok(userTask) {
    userTask = userTask || this.userTask;
    let list = userTask.multiUserTask && userTask.multiUserTask.length && userTask.multiUserTask || [userTask];
    list = list.reverse();
    let flowModelInstance = new FlowModelInstance(this.supportInstance.getModel());
    if (list.length === 1) {
      flowModelInstance.addBranch(list[0], this.nodeId)
    } else {
      flowModelInstance.addNodeAfter(list[0], this.nodeId);
      this.nodeId = list[0].id
      for (let i = 1; i < list.length; i++) {
        flowModelInstance.addBranch(list[i], this.nodeId)
      }
    }
    this.supportInstance.setModel(flowModelInstance.getModelString());
  }
}